#include "ScenePrecompiled.hxx"
#include "SceneMeshContext.hxx"
#include "InternalMeshContextImpl.hxx"

Eifersucht::MeshContext::Deformation::Deformation()
{
	vnSkin.clear();
}

Eifersucht::MeshContext::Deformation::~Deformation()
{
	for ( auto pSkin : vnSkin ) _Delete_pointer( pSkin );
	vnSkin.clear();
}

Eifersucht::MeshContext::Skin::Skin()
{
	vnBones.clear();
}

Eifersucht::MeshContext::Skin::~Skin()
{
	for ( auto pBone : vnBones ) _Delete_pointer( pBone );
	vnBones.clear();
}

Eifersucht::MeshContext::Bone::Bone()
{
	pWeights = nullptr;
	pIndices = nullptr;
}

Eifersucht::MeshContext::Bone::~Bone()
{
	_Delete_pointer_array( pWeights );
	_Delete_pointer_array( pIndices );
}

void Eifersucht::MeshContext::InternalRestart()
{
	if ( !m_pImpl )
	{
		m_pImpl = new _Internal_impl(this);
	}
}

void Eifersucht::MeshContext::InternalRelease()
{
	Safe_Delete(m_pImpl);
}

Eifersucht::MeshContext::MeshContext() : 
	SceneChildContext(),
	m_pImpl(nullptr)
{
	// Indicate that this is a mesh context
	SceneChildContext::m_eCtx = Mesh;
	InternalRestart();
}

Eifersucht::MeshContext::~MeshContext()
{
	InternalRelease();
}

void Eifersucht::MeshContext::ReleaseExternalResources()
{
	PrintToDebugWindowOnly8( 
		"Eifersucht. MeshContext. "
		"Releasing external resources." 
		);

	Safe_Delete(m_pImpl);
}